<?php

/**
 * RequestedDocumentSpecification.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * Amazon Shipping API.
 *
 * The Amazon Shipping API is designed to support outbound shipping use cases both for orders originating on Amazon-owned marketplaces as well as external channels/marketplaces. With these APIs, you can request shipping rates, create shipments, cancel shipments, and track shipments.
 *
 * The version of the OpenAPI document: v2
 * Contact: swa-api-core@amazon.com
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\shipping\v2;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * RequestedDocumentSpecification Class Doc Comment.
 *
 * @category Class
 *
 * @description The document specifications requested. For calls to the purchaseShipment operation, the shipment purchase fails if the specified document specifications are not among those returned in the response to the getRates operation.
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class RequestedDocumentSpecification implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'RequestedDocumentSpecification';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'format' => '\SpApi\Model\shipping\v2\DocumentFormat',
        'size' => '\SpApi\Model\shipping\v2\DocumentSize',
        'dpi' => 'int',
        'page_layout' => 'string',
        'need_file_joining' => 'bool',
        'requested_document_types' => '\SpApi\Model\shipping\v2\DocumentType[]',
        'requested_label_customization' => '\SpApi\Model\shipping\v2\RequestedLabelCustomization'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'format' => null,
        'size' => null,
        'dpi' => null,
        'page_layout' => null,
        'need_file_joining' => null,
        'requested_document_types' => null,
        'requested_label_customization' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'format' => false,
        'size' => false,
        'dpi' => true,
        'page_layout' => true,
        'need_file_joining' => false,
        'requested_document_types' => false,
        'requested_label_customization' => true,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'format' => 'format',
        'size' => 'size',
        'dpi' => 'dpi',
        'page_layout' => 'pageLayout',
        'need_file_joining' => 'needFileJoining',
        'requested_document_types' => 'requestedDocumentTypes',
        'requested_label_customization' => 'requestedLabelCustomization',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'format' => 'setFormat',
        'size' => 'setSize',
        'dpi' => 'setDpi',
        'page_layout' => 'setPageLayout',
        'need_file_joining' => 'setNeedFileJoining',
        'requested_document_types' => 'setRequestedDocumentTypes',
        'requested_label_customization' => 'setRequestedLabelCustomization',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'format' => 'getFormat',
        'size' => 'getSize',
        'dpi' => 'getDpi',
        'page_layout' => 'getPageLayout',
        'need_file_joining' => 'getNeedFileJoining',
        'requested_document_types' => 'getRequestedDocumentTypes',
        'requested_label_customization' => 'getRequestedLabelCustomization',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('format', $data ?? [], null);
        $this->setIfExists('size', $data ?? [], null);
        $this->setIfExists('dpi', $data ?? [], null);
        $this->setIfExists('page_layout', $data ?? [], null);
        $this->setIfExists('need_file_joining', $data ?? [], null);
        $this->setIfExists('requested_document_types', $data ?? [], null);
        $this->setIfExists('requested_label_customization', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (null === $this->container['format']) {
            $invalidProperties[] = "'format' can't be null";
        }
        if (null === $this->container['size']) {
            $invalidProperties[] = "'size' can't be null";
        }
        if (null === $this->container['need_file_joining']) {
            $invalidProperties[] = "'need_file_joining' can't be null";
        }
        if (null === $this->container['requested_document_types']) {
            $invalidProperties[] = "'requested_document_types' can't be null";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets format.
     */
    public function getFormat(): string
    {
        return $this->container['format'];
    }

    /**
     * Sets format.
     *
     * @param string $format format
     */
    public function setFormat(string $format): self
    {
        if (is_null($format)) {
            throw new \InvalidArgumentException('non-nullable format cannot be null');
        }
        $this->container['format'] = $format;

        return $this;
    }

    /**
     * Gets size.
     */
    public function getSize(): DocumentSize
    {
        return $this->container['size'];
    }

    /**
     * Sets size.
     *
     * @param DocumentSize $size size
     */
    public function setSize(DocumentSize $size): self
    {
        if (is_null($size)) {
            throw new \InvalidArgumentException('non-nullable size cannot be null');
        }
        $this->container['size'] = $size;

        return $this;
    }

    /**
     * Gets dpi.
     */
    public function getDpi(): ?int
    {
        return $this->container['dpi'];
    }

    /**
     * Sets dpi.
     *
     * @param null|int $dpi The dots per inch (DPI) value used in printing. This value represents a measure of the resolution of the document.
     */
    public function setDpi(?int $dpi): self
    {
        if (is_null($dpi)) {
            array_push($this->openAPINullablesSetToNull, 'dpi');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('dpi', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['dpi'] = $dpi;

        return $this;
    }

    /**
     * Gets page_layout.
     */
    public function getPageLayout(): ?string
    {
        return $this->container['page_layout'];
    }

    /**
     * Sets page_layout.
     *
     * @param null|string $page_layout Indicates the position of the label on the paper. Should be the same value as returned in getRates response.
     */
    public function setPageLayout(?string $page_layout): self
    {
        if (is_null($page_layout)) {
            array_push($this->openAPINullablesSetToNull, 'page_layout');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('page_layout', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['page_layout'] = $page_layout;

        return $this;
    }

    /**
     * Gets need_file_joining.
     */
    public function getNeedFileJoining(): bool
    {
        return $this->container['need_file_joining'];
    }

    /**
     * Sets need_file_joining.
     *
     * @param bool $need_file_joining When true, files should be stitched together. Otherwise, files should be returned separately. Defaults to false.
     */
    public function setNeedFileJoining(bool $need_file_joining): self
    {
        if (is_null($need_file_joining)) {
            throw new \InvalidArgumentException('non-nullable need_file_joining cannot be null');
        }
        $this->container['need_file_joining'] = $need_file_joining;

        return $this;
    }

    /**
     * Gets requested_document_types.
     */
    public function getRequestedDocumentTypes(): array
    {
        return $this->container['requested_document_types'];
    }

    /**
     * Sets requested_document_types.
     *
     * @param array $requested_document_types a list of the document types requested
     */
    public function setRequestedDocumentTypes(array $requested_document_types): self
    {
        if (is_null($requested_document_types)) {
            throw new \InvalidArgumentException('non-nullable requested_document_types cannot be null');
        }
        $this->container['requested_document_types'] = $requested_document_types;

        return $this;
    }

    /**
     * Gets requested_label_customization.
     */
    public function getRequestedLabelCustomization(): ?RequestedLabelCustomization
    {
        return $this->container['requested_label_customization'];
    }

    /**
     * Sets requested_label_customization.
     *
     * @param null|RequestedLabelCustomization $requested_label_customization requested_label_customization
     */
    public function setRequestedLabelCustomization(?RequestedLabelCustomization $requested_label_customization): self
    {
        if (is_null($requested_label_customization)) {
            array_push($this->openAPINullablesSetToNull, 'requested_label_customization');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('requested_label_customization', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['requested_label_customization'] = $requested_label_customization;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
